package c04.reentrantlock;

import lombok.extern.slf4j.Slf4j;
import util.Sleeper;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 测试可中断
 *
 */
@Slf4j(topic = "c.InterruptTest2")
public class InterruptTest2 {
    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();

        Thread t1 = new Thread(() -> {
            log.debug("启动...");
            lock.lock();
            try {
                log.debug("获得了锁");
            } finally {
                lock.unlock();
            }
        }, "t1");


        lock.lock();
        log.debug("获得了锁");
        t1.start();
        try {
            Sleeper.sleep(1);
            t1.interrupt();
            log.debug("执行打断");
            Sleeper.sleep(1);
        } finally {
            log.debug("释放了锁");
            lock.unlock();
        }
    }
}
